<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="icon" href="/static/images/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/static/images/favicon.ico" type="image/x-icon" />
<script type="text/javascript" src="/static/js/head.js"></script>
<link rel="stylesheet" type="text/css" href="/static/css/login.css" />
</head>
<body>
	<div class="header">
	</div>
	<div class="denglu">
		<input class="name" type="text" id="username" name="username" value=""/>
		<input class="password" type="password" id="password" name="password" value=""/>
		<div class="btn" id="loginbtn"></div>
	</div>
<script type="text/javascript">
$(function(){
	$.ajaxSetup({crossDomain: true, xhrFields: {withCredentials: true}});
});
	$('#loginbtn').click(function() {
			var username = $('#username').val();
			var password = $('#password').val();
			if (username != null && username != "" && password != null && password != "") {
				$.ajax({
					url : getHost()+"/user/login",
					type : "POST",
					data : JSON.stringify({
					    username : username,
					    password : password
					}),
					async : false,
					dataType : "json",
					contentType: 'application/json;charset=UTF-8',
					beforeSend: function(xhr) {
		                xhr.withCredentials = true;
		            },
		            crossDomain:true,
					success : function(data) {
						if (data.code==200&&typeof(data.data) == "object"&&typeof(data.data.item) == "object"&&data.data.item.id>0) {
							sessionStorage.setItem('userid',data.data.item.id);
							sessionStorage.setItem('nickname',data.data.item.nickname);
							sessionStorage.setItem('username',data.data.item.username);
							rolelist = data.data.item.roleList;
							var rolestr = "";
							if(rolelist&&rolelist!=null){
								for(keys in rolelist){
									rolestr += rolelist[keys].name + ",";
								}
								rolestr = rolestr.substr(0,rolestr.length-1);
							}
							sessionStorage.setItem('role',rolestr);
							window.location.href = "/index.html";
						} else{
							$('#username').focus();
							$('#password').focus();
						}
					}
				});
			} else {
				$.messager.alert("提示","请输入账号密码！");
				$('#username').focus();
				$('#password').focus();
			}
});
	$(document).keydown(function(event){ 
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if(keyCode==13){
			$("#loginbtn").click();
		}
	});

</script>
</body>
</html>